package test.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsUnmodifiableList {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(1);
        list.add(2);
        list.add(5);
        list.add(4);
        
        // uList 不可改，但 list 的修改仍然会导致 uList 的修改
        List<Integer> uList = Collections.unmodifiableList(list);
        System.out.println(uList);
        list.add(6);
        System.out.println(uList);
//        uList.add(7); // java.lang.UnsupportedOperationException
    }
}
//[3, 1, 2, 5, 4]
//[3, 1, 2, 5, 4, 6]